package org.dark.fund.web;


import org.dark.fund.api.IFundService;
import org.dark.fund.api.dto.FundBaseInfoToday;
import org.dark.fund.api.dto.FundRateRecently;
import org.dark.fund.common.ApiResult;
import org.dark.fund.dao.entity.Fund;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wanlh
 * @since 2021-04-29
 */
@RestController
@RequestMapping("/fund")
public class FundController {

    @Autowired
    private IFundService fundService;

    /**
     * 查询基金
     *
     * @param condition
     * @return
     */
    @GetMapping("/query")
    public ApiResult<Set<Fund>> queryFund(@RequestParam("condition") String condition) {
        return ApiResult.ok(fundService.queryFundAvailable(condition));
    }

    /**
     * 查询基金基本信息 - 包含当日涨跌值
     *
     * @param fundCode
     * @return
     */
    @GetMapping("/detail/{fundCode}")
    public ApiResult<FundBaseInfoToday> detailBaseInfoToday(@PathVariable("fundCode") String fundCode) {
        return ApiResult.ok(fundService.queryFundBaseInfoToday(fundCode));
    }

    /**
     * 业绩走势
     *
     * @param fundCode
     * @param offset
     * @return
     */
    @GetMapping("/detail/{fundCode}/{offset}")
    public ApiResult<FundRateRecently> detailFundRateRecently(@PathVariable("fundCode") String fundCode,
                                                              @PathVariable("offset") int offset) {
        return ApiResult.ok(fundService.queryFundRateRecently(fundCode, offset));
    }

}
